package com.ctgu.蓝桥杯真题.B组2014;

import java.io.*;

/**
 * @author: Backdiy
 * @data: 2021/4/15 20:51
 * @desc:
 */
public class 分糖果8 {
    static int[] num;
    static int n;
    static int ans = 0;

    public static void main(String[] args) throws IOException {
        n = IO.nextInt();
        num = new int[n + 10];
        for (int i = 0; i < n; i++) {
            num[i] = IO.nextInt();
        }
        while (true) {
            if (check()) {
                break;
            }
            int t = num[0];
            for (int i = 0; i < n - 1; i++) {
                num[i] /= 2;
                num[i] += num[i + 1] / 2;
                if (num[i] % 2 == 1) {
                    ans++;
                    num[i]++;
                }
            }
            num[n - 1] /= 2;
            num[n - 1] += t / 2;
            if (num[n - 1] % 2 == 1) {
                ans++;
                num[n - 1]++;
            }
            if (check()) {
                break;
            }
        }
        System.out.println(ans);
    }

    static boolean check() {
        int t = num[0];
        for (int i = 1; i < n; i++) {
            if (num[i] != t) {
                return false;
            }
        }
        return true;
    }

    static class IO {
        static StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        static PrintWriter out = new PrintWriter((new OutputStreamWriter(System.out)));
        static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        static int nextInt() throws IOException {
            streamTokenizer.nextToken();
            return (int) streamTokenizer.nval;
        }

        static double nextDouble() throws IOException {
            streamTokenizer.nextToken();
            return streamTokenizer.nval;
        }

        static long nextLong() throws IOException {
            streamTokenizer.nextToken();
            return (long) streamTokenizer.nval;
        }

        static String nextLine() throws IOException {
            return bufferedReader.readLine();
        }

        static char next() throws IOException {
            return (char) bufferedReader.read();
        }
    }
}
